//
//  FKLoginTool.m
//  FKLibraryExample
//
//  Created by frank on 2018/8/16.
//  Copyright © 2018年 zmosa - frank. All rights reserved.
//

#import "FKLoginTool.h"
#import "FKNavVC.h"
#import "FKLoginVC.h"
#import "FKTabBarVC.h"

@implementation FKLoginTool

+ (void)showLoginByPresent
{
    FKLoginVC *login = [[FKLoginVC alloc] init];
    FKNavVC *nav = [[FKNavVC alloc] initWithRootViewController:login];
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window.rootViewController presentViewController:nav animated:YES completion:nil];
}

+ (void)showLoginBySwitchRootVC
{
    FKLoginVC *login = [[FKLoginVC alloc] init];
    FKNavVC *nav = [[FKNavVC alloc] initWithRootViewController:login];
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    window.rootViewController = nav;
}

+ (void)checkLogin:(void (^)(void))completion
{
//    NSDictionary *loginInfo = [FKCacheTool loginInfo];
//    if (!loginInfo) {
//        [self showLoginByPresent];
//    } else {
//        if (completion) completion();
//    }
    
    
    if ([FKCacheTool isLogin]) {
        if (completion) completion();
    } else {
        [self showLoginByPresent];
    }
    
//#warning 注意，一定要绑定手机号才算登陆了
//    // 能取到用户信息证明，一定是绑定了手机号的，没绑定手机号，就不缓存用户信息
//    NSDictionary *userInfo = [FKCacheTool userInfo];
//    if (!userInfo) {
//        [self showLoginByPresent];
//    } else {
//        if (completion) completion();
//    }
}

+ (void)changeRootVC
{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    window.rootViewController = [[FKTabBarVC alloc] init];
}

@end
